#pragma once
#include "event_handler.h"
#include <mutex>
#include <string>

class ThreadPool;

/// Echo 连接：演示“读 -> 解析 -> 计算 -> 写回”流程
class EchoConnection : public EventHandler {
public:
    EchoConnection(EventLoop& loop, int fd, ThreadPool& computePool);
    ~EchoConnection() override;

    void handleEvent(uint32_t events) override;

private:
    void submitComputeTask();
    void onComputeDone(std::string response);
    void shutdownInLoop();

    ThreadPool& computePool_;
    std::mutex mutex_;
    std::string readBuf_;
    std::string writeBuf_;
    bool closed_{false};
};